package com.chenchao.thread;

/**
 * @encoding : UTF-8
 * @Time : 2020/12/5 9:28
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.thread.Test21.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 */
public class Test21 {
    public static void main(String[] args) throws InterruptedException {
        Person person = new Person();
        new Thread(person::setCount).start();
        new Thread(person::getCount).start();
        //new Thread(person).start();
        Thread.sleep(2000);
    }
}
class Person implements Runnable{
    int count=10;
    public synchronized void setCount()  {
        System.out.println("count:"+count--);
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("count:"+count);
    }
    public synchronized void getCount()  {
        System.out.println("get:"+count--);
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("get:"+count);
    }

    @Override
    public void run() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("run"+this.count--);
    }
}